package com.crm.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.crm.common.ResVo;
import com.crm.entity.Goods;
import com.crm.service.GoodsService;
import com.spring4all.swagger.EnableSwagger2Doc;

import io.swagger.annotations.Api;

@RestController
@EnableSwagger2Doc
@RequestMapping("/goods")
@Api(tags = "商品管理")
public class GoodsController {

	@Autowired
	private GoodsService goodsService;
	
	@GetMapping("/findGoods/{pageIndex}")
	@ApiOperation("查询商品,带分页")
	public ResVo<Object> findGoods(@PathVariable @ApiParam("页码") Integer pageIndex) {
		Page<Goods> message = goodsService.findGoods(pageIndex);
		return ResVo.success(message);
	}
	
	@GetMapping("/findGoodsByPage/{pageIndex}")
	@ApiOperation("查询商品,带分页")
	public ResVo<Object> findGoodsByPage(@PathVariable @ApiParam("页码") Integer pageIndex,@RequestParam(value="title",required=false) @ApiParam("商品标题") String title) {
		Page<Goods> message = goodsService.findGoodsByPage(pageIndex,title);
		return ResVo.success(message);
	}
	
	
	@GetMapping("/findGoodsById/{id}")
	@ApiOperation("按商品id查询商品")
	public ResVo<Object> findGoodsById(@PathVariable @ApiParam("商品id") String id) {
		Goods message = goodsService.findGoodsById(id);
		return ResVo.success(message);
	}
	
	@PostMapping("/addGoods")
	@ApiOperation("添加商品信息")
	public ResVo<Object> addGoods(@RequestBody Goods goods) {
		goodsService.addGoods(goods);
		return ResVo.defaultSuccess();
	}
	
	@PostMapping("/findGoodsByIds")
	@ApiOperation("按商品id列表查询商品")
	public ResVo<Object> findGoodsByIds(@RequestBody List<String> goodsIds) {
		List<Goods> message = goodsService.findGoodsByIds(goodsIds);
		return ResVo.success(message);
	}
	
	@GetMapping("/findGoodsByIds/{goodsIds}")
	@ApiOperation("按商品id列表查询商品")
	public ResVo<Object> findGoodsByIds(@PathVariable @ApiParam("商品ids")String goodsIds) {
		List<Goods> message = goodsService.findGoodsByIds(goodsIds);
		return ResVo.success(message);
	}
	
}
